package com.example.demo.mapper;

import com.example.demo.pojo.entity.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommentMapper {
    @Insert("insert into comment(parent_id,reply_id, from_id, item_id,content, create_time, update_time) " +
            "values (#{parentId}, #{replyId}, #{fromId}, #{itemId}, #{content}, now(), now())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    boolean addComment(Comment comment);

    @Select("select item_id from comment where id = #{id}")
    Long selectItemIdById(Long id);

    @Select("select parent_id from comment where id = #{id}")
    Long selectParentIdById(Long id);

    @Select("select from_id from comment where id = #{id}")
    Long selectUserIdById(Long id);

    @Delete("delete from comment where id = #{id}")
    boolean deleteCommentById(Long id);

    @Delete("delete from comment where item_id = #{itemId}")
    boolean deleteCommentByItemId(Long itemId);

    @Select("select id from comment where item_id = #{itemId}")
    List<Long> selectIdListByItemId(Long itemId);

    @Select("select id from comment where parent_id = #{parentId}")
    List<Long> selectIdListByParentId(Long parentId);

    @Select("select * from comment where item_id = #{item_id} order by id")
    List<Comment> selectCommentListByItemId(Long itemId);

    @Select("select * from comment where from_id = #{fromId} order by id desc")
    List<Comment> selectCommentListByUserId(Long userId);
}
